{include file="public/header"}

{include file="public/style"}       
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>首页</el-breadcrumb-item>
            <el-breadcrumb-item>物流管理</el-breadcrumb-item>
            <el-breadcrumb-item>快递服务商列表</el-breadcrumb-item>
        </el-breadcrumb>
        <br>
            <el-card >
                <div style="display: flex;align-items: center;justify-content: flex-start;">
                    <el-form :inline="true" :model="searchForm" size="small"  ref="refsearchForm">                
                        <el-form-item label="服务商名称">                     
                           <el-input v-model="searchForm.name_Cn" placeholder="请输入服务商名称" filterable clearable></el-input>
                        </el-form-item>         
                         <el-form-item label="服务商状态">
                            <el-select v-model="searchForm.status" placeholder="请选择服务商状态" filterable clearable>
                                <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>                       
    
                        <el-form-item>
                            <el-button type="primary"  size="small" plain @click="getSearch" icon="el-icon-search" v-cloak>查询</el-button>
                        </el-form-item>          
                      </el-form>
                    
                    <div style="margin-left: auto;margin-bottom: 20px;margin-right: 20px;" >
                            <el-button  type="primary"   @click="create" size="small"  icon="el-icon-edit" >添加快递服务商</el-button>       
                    </div>
                </div>  
                
                
                <el-table :data="tablelist"   style="width: 100%;margin-bottom: 20px;"  row-key="id"  border >
                    <el-table-column   prop="id" label="ID" width="80"> </el-table-column>
                    <el-table-column   prop="name_Cn" label="服务商名称" > </el-table-column>  
                    <el-table-column   prop="name_En" label="服务商代号" ></el-table-column>   
                    <el-table-column   prop="status"  label="服务商状态" width="150"> 
                        <template v-slot="{row}" >
                            <span v-if="row.status===1">
                                <el-tag type="success">启用</el-tag>
                            </span>
                            <span   v-if="row.status===0">
                                <el-tag type="danger">禁用</el-tag>                                                
                            </span>
                       </template>          
                    </el-table-column>
                    <el-table-column   prop="createtime" label="添加时间" width="180"> </el-table-column>  

                    <el-table-column  fixed="right" label="操作" width="180">
                        <template v-slot="{row}">
                            <el-button type="primary"  plain  icon="el-icon-edit"  @click="editor(row)" >编辑 </el-button>
                                  
                        </template>
                    </el-table-column>
                </el-table>    
                <!-- page -->
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="searchForm.pagenum" :page-sizes="[20,50,100, 150, 300,500,1000,2000]"
                    :page-size="searchForm.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
                </el-pagination>  
            </el-card>


              <!-- 修改编辑弹窗 -->
            <el-dialog :title="title" :visible.sync="isproviderVisible " width="600px" :close-on-click-modal="false">
                <el-form :inline="true" :model="createForm" size="mini"  :rules="isproviderules"  ref="refsearchForm" label-width="100px"  >             

                    <el-form-item prop="name_Cn" label="服务商名称:">
                        <el-input v-model="createForm.name_Cn" placeholder="请输入服务商名称" style="width: 330px;" clearable></el-input>
                    </el-form-item>
                    <el-form-item prop="name_En" label="服务商代号:">
                        <el-input v-model="createForm.name_En" placeholder="请输入服务商代号" style="width: 330px;" clearable></el-input>
                    </el-form-item>
                    <el-form-item prop="account_name" label="服务商账户:">
                        <el-input v-model="createForm.account_name" placeholder="请输入服务商名称" style="width: 330px;" clearable></el-input>
                    </el-form-item>
                    <el-form-item prop="account_password" label="服务商密码:">
                        <el-input v-model="createForm.account_password" placeholder="请输入服务商密码" style="width: 330px;" clearable></el-input>
                    </el-form-item>
                    <el-form-item prop="authorizeCode" label="服务商授权码:">
                        <el-input v-model="createForm.authorizeCode" placeholder="请输入服务商密码" style="width: 330px;" clearable></el-input>
                    </el-form-item>
                    
                    <el-form-item  label="店铺状态:">                                  
                        <el-radio-group v-model="createForm.status"  style="margin-left: 10px;" @change="handleSwitchChange">         
                            <template>            
                            <el-radio :label="1"  >正常</el-radio>   
                            <el-radio :label="0"  >关闭</el-radio>                     
                        </template>
                        </el-radio-group>                
                    </el-form-item> 
             

                <div>                                   
                    <el-form-item>
                        <el-button type="primary" @click="checkSubmits">确认</el-button>
                        <el-button type="primary" plain @click="close"> 取消</el-button>
                    </el-form-item>
                </div>
                </el-form>
            </el-dialog>   
    </div>

    <script>
        new Vue({
            el: '#app',
            data: function () {
                return {       
                    title:'',           
                    isproviderVisible:false,//控制配置弹窗
                    status:[
                        {
                            value: 2,
                            label: '禁用'
                        },
                        {
                            value: 1,
                            label: '正常'
                        }
                    ],
                    // 状态是否正常      
                
                    total:0,   //分页总页数      
                    tablelist:[] ,              
                    searchForm: {                              
                        name_Cn: '',                                             
                        status: '',         
                        pagesize: 20,
                        pagenum: 1,
                        
                    },                     
                    platform:[], 
                    createForm:{
                        name_Cn:'',          
                        name_En:'',                      
                        status: '', 
                        account_name:'', 
                        account_password:'',  
                        authorizeCode:'',           
                    },
                    isproviderules: {
                        name_Cn: [
                            { required: true, message: '请输入服务商名称', trigger: 'blur' },
                        ],  
                        name_En: [
                            { required: true, message: '请输入服务商代号', trigger: 'blur' },
                        ],   
                        account_name   : [
                            { required: true, message: '请输入服务商账户', trigger: 'blur' },
                        ],   
                        account_password   : [
                            { required: true, message: '请输入服务密码', trigger: 'blur' },
                        ],          
                    }
                }
            },
            mounted(){        
                this.getSearch()
            },
            methods: {        

                async getDatalist() {
                    const res = await axios.post('/admin/logistics/provider', {params: this.searchForm})
                        if (res.status !== 1) {
                            return this.$message.error(res.info);
                        }
                    this.total = res.info.total
                    this.tablelist = res.info.list
                },
                    
                handleSizeChange(newSize) {
                    this.searchForm.pagesize = newSize
                    this.getDatalist()
                },
                handleCurrentChange(newPage) {
                    this.searchForm.pagenum = newPage
                    this.getDatalist()
                },              
                getSearch() {
                    this.searchForm.pagenum = 1
                    this.getDatalist()
                },        
                //编辑
                editor(row){         
                    this.title = '编辑快递服务商'
                    this.isproviderVisible = true             
                    this.createForm=JSON.parse(JSON.stringify(row));                                    
                },
                //添加快递服务商
                create(){
                    this.title = '添加快递服务商'
                    this.isproviderVisible = true
                    this.createForm.id = ''
                    this.createForm.status = 1         
                    this.createForm.name_Cn = ''        
                    this.createForm.name_En = ''      
                    this.createForm.account_name = ''        
                    this.createForm.account_password = ''  
                    this.createForm.authorizeCode = ''        
                },      
                //确认提交修改
                async checkSubmits(){
                    this.$refs.refsearchForm.validate(async valid => {
                        if (!valid) return;
                        let loading = this.$loading({
                            lock: true,
                            text: '数据加载中···',
                            spinner: 'el-icon-loading',
                            background: 'rgba(0, 0, 0, 0.7)'
                            });
                        axios.post('/admin/logistics/provider_create', {params: this.createForm}).then(res => {
                            loading.close()
                            if (res.status !== 1) {
                                return this.$message.error(res.info);                  
                            }
                        
                            this.$message.success('操作成功');
                            this.isproviderVisible = false
                            this.getDatalist()
                        }).catch(err => {
                            console.log(err)
                        })
                    })
                },  
                //修改是否是服务商
                handleSwitchChange(row) {
                    if(row.status==0){
                       this.$confirm('确认关闭该服务商,如果关闭，则会下面快递渠道也会无效哦？', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            closeOnClickModal: false, // 禁用点击遮罩关闭弹窗
                            type: 'warning'
                        }).catch(() => {
                            this.createForm.status = 1;
                        });         
                    }               
                },
                //    
                //关闭弹窗
                close(){
                    this.isproviderVisible=false  
                },             
                
                
            }
        })
    </script>
 </body> 
</html>
